package com.firexxx.study.util;

import org.apache.logging.log4j.util.Strings;

/**
 * @description: TODO
 * @throws:
 * @author: zhuangzhang2
 * @date: 2020/04/09 19:05
 */
public class ExceptionUtil {

    public static String getMergedMessage(Throwable ex) {
        if (ex == null) {
            return null;
        } else {
            return ex.getCause() == null
                    ? ex.toString()
                    : ex.toString() + "/" + getMergedMessage(ex.getCause());
        }
    }

    public static String getFirstNonNullMessage(Throwable ex) {
        if (ex == null) {
            return null;
        } else {
            return Strings.isBlank(ex.getMessage())
                    ? getFirstNonNullMessage(ex.getCause())
                    : ex.getMessage();
        }
    }

}